<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/6/3
 * Time: 10:53
 */

namespace app\applet\model;


use think\Db;
use think\Exception;

class Asset
{
    /**
     * 获取用户资产
     */
    public function getMemberAsset($member_id){
        $assert=Db::name("member_asset")
            ->where(['member_id'=>$member_id])
            ->field("seven_frozen_score,score,frozen_score,max_thaw_score,coin,credit_ensure,ad_share,score_trans_frozen")
            ->find();
        if(empty($assert)){
            $assert['max_thaw_score']=0;
            $assert['score']=0;
            $assert['frozen_score']=0;
            $assert['coin']=0;
            $assert['credit_ensure']=0;
            $assert['ad_share']=0;
            //积分担保转赠冻结余额
            $assert['score_trans_frozen']=0;
            $assert['seven_frozen_score']=0;

        }


        return $assert;
    }

    /**
     * 获取冻结积分记录列表
     */
    public function getFrozenScoreList($current_page,$page_num,$where){

        $data = Db::name("member_asset_log")
            ->field("source_type,type,amount,description,create_time")
            ->where($where)
            ->page($current_page,$page_num)
            ->order("update_time desc")
            ->select();
        $total_num = Db::name("member_asset_log")
            ->where($where)
            ->count();

        $total_amount = Db::name("member_asset_log")
            ->where($where)
            ->sum("amount");
        $list['current_page'] = $current_page;
        $list['total_page'] = ceil($total_num / $page_num);
        $list['total_amount'] = $total_amount;
        $list['page_num'] = $page_num;
        $list['total_num'] = $total_num;
        $list['data'] = $data;
        return $list;

    }
    /**
     * 获取积分记录列表
     */
   public function getScoreList($current_page,$page_num,$where,$input){
       if($current_page==1){//获取缘由
           $changeType= $input['change_type'];
           $type=$input['type'];
           $logTypeList=Db::name("asset_log_type")->where(['type'=>$type,'atype'=>$changeType])->field("te_id,name")->select();
           $list['type_list']= $logTypeList;
       }
       $data = Db::name("member_asset_log")
           ->field("source_type,type,amount,description,create_time")
           ->where($where)
           ->page($current_page,$page_num)
           ->order("update_time desc")
           ->select();
       $total_num = Db::name("member_asset_log")
           ->where($where)
           ->count();

       $total_amount = Db::name("member_asset_log")
           ->where($where)
           ->sum("amount");
       $list['current_page'] = $current_page;
       $list['total_page'] = ceil($total_num / $page_num);
       $list['total_amount'] = $total_amount;
       $list['page_num'] = $page_num;
       $list['total_num'] = $total_num;
       $list['log_list'] = $data;
       return $list;

   }

    /**
     * 获取金币记录列表
     */
    public function getCoinList($current_page,$page_num,$where,$input){
        if($current_page==1){//获取缘由
            $changeType=$input['change_type'];
            $type=$input['type'];
            $logTypeList=Db::name("asset_log_type")->where(['type'=>$type,'atype'=>$changeType])->field("te_id,name")->select();
            $list['type_list']= $logTypeList;
        }
        $data = Db::name("member_asset_log")
            ->field("source_type,type,amount,description,create_time")
            ->where($where)
            ->page($current_page,$page_num)
            ->order("update_time desc")
            ->select();
        $total_num = Db::name("member_asset_log")
            ->where($where)
            ->count();
        $total_amount = Db::name("member_asset_log")
            ->where($where)
            ->sum("amount");
        $list['current_page'] = $current_page;
        $list['total_page'] = ceil($total_num / $page_num);
        $list['total_amount'] = $total_amount;
        $list['page_num'] = $page_num;
        $list['total_num'] = $total_num;
        $list['log_list'] = $data;
        return $list;

    }

    /**
     * 获取微信支付记录列表
     */
    public function getWxpayList($current_page,$page_num,$where,$input){
        if($current_page==1){//获取缘由
            $changeType= $input['change_type'];
            $type=2;
            $logTypeList=Db::name("asset_log_type")->where(['type'=>$type,'atype'=>$changeType])->field("te_id,name")->select();
            $list['type_list']= $logTypeList;
        }

        $data = Db::name("member_asset_log")
            ->field("type,amount,description,create_time")
            ->where($where)
            ->page($current_page,$page_num)
            ->order("update_time desc")
            ->select();
        $total_num = Db::name("member_asset_log")
            ->where($where)
            ->count();

        $total_amount = Db::name("member_asset_log")
            ->where($where)
            ->sum("amount");

        $list['current_page'] = $current_page;
        $list['total_page'] = ceil($total_num / $page_num);
        $list['total_amount'] = $total_amount;
        $list['page_num'] = $page_num;
        $list['total_num'] = $total_num;
        $list['log_list'] = $data;
        return $list;
    }
}